package com.zhoujing.myrabbitmq.consumer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.util.Date;

/**
 * @author 周敬
 * @version 1.0
 * @createTime 2022/7/19-23:26-星期二
 *
 * 延时队列
 * 消费者
 */
@Slf4j
@Component
public class DelayQueueConsumer {

    /**
     * 监听消息
     * @param message 消息
     * @throws UnsupportedEncodingException
     */
    @RabbitListener(queues = "delayed.queue")
    public void receiveDelayQueue(Message message) throws UnsupportedEncodingException {
        String msg = new String(message.getBody(),"UTF-8");
        log.info("当前时间为：{}，收到的延时消息为：{}",new Date(),msg);
    }
}
